/*
剑指 Offer 57. 和为s的两个数字
解题思路：双指针思想
 */
public class Offer57 {

  public static void main(String[] args) {
    int[] sum = Offer57.twoSum(new int[]{2, 7, 11, 15}, 9);
    for (int i : sum) {
      System.out.println(i);
    }
  }

  public static int[] twoSum(int[] nums, int target) {
    int l = 0;
    int r = nums.length - 1;
    while(l < r){
      int sum = nums[l] + nums[r];
      if (sum > target){
        r--;
      }else if (sum < target){
        l++;
      }else {
        return new int[]{nums[l],nums[r]};
      }
    }
    return new int[0];
  }
}
